<template>
  <div class="operation-monitoring">
    <div class="content-title">
      <div class="title-left">
        <img
          class="title-left-img"
          src="@/assets/img/water/title-icon.png"
          alt=""
        />
        <span class="title-left-span">全天总排水量</span>
      </div>
      <div class="title-right">
        <span class="title-right-num">3733</span><span class="company">m³</span>
      </div>
    </div>
    <div class="content-list">
      <div v-for="(it, i) in showLists" :key="i" class="content-item">
        <div class="item-left">
          <div v-for="(item, index) in it.pumpList" :key="index" class="inner-box">
            <div class="item-title">
              <img v-if="item.runStatus === '运行' " src="@/assets/img/water/success.png">
              <img v-if="item.runStatus === '故障' " src="@/assets/img/water/fault.png">
              <img v-if="item.runStatus === '停止' " src="@/assets/img/water/stop.png">
              <span>{{ item.pumpName }}</span>
              <span
              :style="{width:'3.125rem',height:'1rem','margin-left':'1.25rem','font-size':'.75rem',
              'text-align':'center','display':'inline-block',
              color:color(item.runStatus).color,'background-color':color(item.runStatus).bgcolor}">
                {{item.runStatus}}
              </span>
            </div>
            <div class="title-box">
              <div class="title-info">
                <div class="">流量</div>
                <div>
                  <span class="num-text">{{ item.sbScFy }}</span>
                  <span class="unit-text">m³/h</span>
                </div>
              </div>
              <div class="title-info">
                <div class="">排水量</div>
                  <div>
                    <span class="num-text">{{ item.sbScFy }}</span>
                    <span class="unit-text">m³</span>
                  </div>
                </div>
              </div>
            <div class="item-content">
              <div class="left-box">
                <div class="box">
                  <div class="box-info">
                    <div>正压</div>
                    <div>
                      <span class="num-text">{{ item.sbScFy }}</span>
                      <span class="unit-text">MPa</span>
                    </div>
                  </div>
                  <div class="box-info">
                    <div>负压</div>
                    <div>
                      <span class="num-text">{{ item.sbScZy }}</span>
                      <span class="unit-text">MPa</span>
                    </div>
                  </div>
                </div>

                <div class="box">
                  <div class="box-info">
                    <div>前轴温度</div>
                    <div>
                      <span class="num-text">{{ item.sbScBqzwd }}</span>
                      <span class="unit-text">℃</span>
                    </div>
                  </div>
                  <div class="box-info">
                    <div>后轴温度</div>
                    <div>
                      <span class="num-text">{{ item.sbScBzhwd }}</span>
                      <span class="unit-text">℃</span>
                    </div>
                  </div>
                </div>
              </div>

              <div class="center-box">
                <div class="center-list" :class="{'flex-start': item.valveList.length > 3}">
                  <div v-for="(ele, j) in item.valveList" :key="j" class="center-item">
                    <div class="item-row">
                      <img v-if="ele.valveStatus === '完全打开' " src="@/assets/img/water/open.png">
                      <img v-else-if="ele.valveStatus === '完全关闭' " src="@/assets/img/water/close.png">
                      <img v-else src="@/assets/img/water/other.png">
                      <div v-if="ele.valveStatus === '故障'">
                        <el-tooltip class="item" effect="dark" placement="bottom-start">
                          <div slot="content" style="color: #EF303B" v-if="ele.valveErrorMsg.length>0">
                            <span v-for="(v, vi) in ele.valveErrorMsg" :key="vi">{{ v }}<br></span>
                          </div>
                          <div slot="content" style="color: #EF303B" v-else>
                            <span>暂无故障原因</span>
                          </div>
                          <div class="it-name alarm-red">{{ ele.valveName }}</div>
                        </el-tooltip>
                      </div>
                      <div v-else class="it-name">{{ ele.valveName }}</div>
                    </div>
                    <div class="item-row two">
                      <div class="msg-text">阀门开度</div>
                      <div v-if="ele.valveOpening" class="it-percentage">{{ ele.valveOpening }}%</div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="item-right">
          <div>{{ it.levelName }}</div>
          <div>
            <span class="level-text">{{ it.currentLevel }}</span>
            <span class="unit-text">m</span>
          </div>
          <div class="progress-wrap">
            <div
              class="progress"
              :style="{height: (it.currentLevel / it.limitLevel) * 100 + '%',}"
              :class="{
                'red': it.currentLevel > it.dangerLevel,
                'white': it.currentLevel < it.lowLevel,
                'cyan': it.currentLevel > it.lowLevel && it.currentLevel < it.highLevel,
                'orange': it.currentLevel > it.highLevel && it.currentLevel < it.dangerLevel,
              }"
            />
            <div
              class="high"
              :style="{height: (it.highLevel / it.limitLevel) * 100 + '%',}"
            />
            <div
              class="low"
              :style="{height: (it.lowLevel / it.limitLevel) * 100 + '%',}"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { monitorInfo } from '../common/titles';
export default {
  data() {
    return {
      lists: []
    };
  },

  components: {},

  computed: {
    routeId() {
      return this.$route.params.id;
    },
    showLists() {
      const data = this.lists;
      const itemObj = {};
      const resArr = [];
      if (data && data.length > 0) {
        for (var i = 0; i < data.length; i++) {
          const item = data[i];
          const name = item.level.levelName;
          if (itemObj[name] === undefined) {
            resArr.push({ 'name': name, ...item.level, 'pumpList': [item] });
            itemObj[name] = resArr.length - 1;
          } else {
            resArr[itemObj[name]].pumpList.push(item);
          }
        }
      }
      return resArr;
    },
    color() {
      return function(status) {
        const info = {};
        switch (status) {
          case '运行':
            info.color = '#57FFAA';
            info.bgcolor = '#19504e';
            break;
          case '故障':
            info.color = '#ef303b';
            info.bgcolor = '#3f1e32';
            break;
          case '停止':
            info.color = '#ADADAD';
            info.bgcolor = '#303d50';
            break;
        }
        return info;
      };
    }
  },

  mounted() {
    this.lists = monitorInfo[this.routeId];
  },

  methods: {}
};
</script>
<style scoped lang="scss">
.operation-monitoring {
  .company{
    color: #8D8D8D;
    font-size: .75rem;
  }
  .content-title {
    width: 20.625rem;
    height: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.625rem;
    .title-left {
      .title-left-img {
        width: 1.25rem;
        height: 1.25rem;
        margin-right: 0.625rem;
        vertical-align: middle;
      }
      .title-left-span {
        font-size: 0.875rem;
        color: #f8f8f8;
        vertical-align: middle;
      }
    }
    .title-right-num {
      color: #00fdff;
      font-size: 1rem;
      margin-right: 0.3125rem;
    }
  }
  .content-list{
    .content-item{
      font-size: $commonContentText;
      color: $light3Grey;
      display: flex;
      justify-content: space-between;
      .item-left{
        flex: 1;
        .item-title{
          display: flex;
          color: $white;
          font-size: $smallHeadingsText;
          height: 1rem;
          line-height: 1rem;
          margin-bottom: 0.9375rem;
          img{
            width: 1rem;
            height: 1rem;
            margin-right: 0.625rem;
          }
        }
        .item-content{
          display: flex;
          justify-content: space-between;
          height: 15rem;
          margin-bottom: 2.125rem;
          .left-box{
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            width: 8.0625rem;
            .box{
              display: flex;
              flex-direction: column;
              justify-content: space-evenly;

              box-sizing: border-box;
              width: 100%;
              height: 7.25rem;
              border-radius: 0.25rem;
              background: $itemBg;
              padding: 0 0.3125rem;
              .box-info{
                color: $light3Grey;
                font-size: $commonContentText;
                display: flex;
                justify-content: space-between;
                .num-text{
                  font-size: $smallHeadingsText;
                  color: $light3Grey;
                }
              }
            }
          }
          .center-box{
            width: 8.0625rem;
            border-radius: 0.25rem;
            background: $itemBg;
            .center-list{
              height: 90%;
              margin-top: 0.625rem;
              overflow-y: auto;
              overflow-x: hidden;
              display: flex;
              flex-direction: column;
              justify-content: center;
              padding:0 0.3125rem;
              &.flex-start{
                justify-content: flex-start;
              }
              .center-item{
                // height: 2.3125rem;
                // line-height: 2.3125rem;
                position: relative;
                margin-bottom: 1.5625rem;

                // display: flex;
                // align-items: center;
                &:last-child{
                  margin-bottom: 0rem;
                }
                .item-row{
                  display: flex;
                  justify-items: center;
                  height: 1rem;
                  line-height: 1rem;
                  &.two{
                    justify-content: space-between;
                    margin-top: 0.625rem;
                  }
                }
                img{
                  width: 1rem;
                  height: 1rem;
                  margin-right: 0.5rem;
                  &.alarm-icon{
                    position: absolute;
                    left: -1.125rem;
                    width: 0.9375rem;
                    height: 0.9375rem;
                    z-index: 9;
                  }
                }
                .it-name{
                  color: $light2Grey;
                  width: 2.625rem;
                  margin-right: 0.5rem;
                  &.alarm-red{
                    color: $red;
                  }
                }
                .msg-text{
                  color: $lightGrey;
                  // margin-right: 0.5rem;
                }
                .it-percentage{
                  // width: 4.0625rem;
                  color: $blue
                }
              }
            }
          }

        }
      }
      .item-right{
        width: 3.25rem;
        margin-left: 0.375rem;
        border-radius: 0.25rem;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background: $itemBg;

        margin-top: 1.875rem;
        margin-bottom: 1.875rem;

        .level-text{
          font-size: $smallHeadingsText;
          height: 1.25rem;
          line-height: 1.5625rem;
        }
        .progress-wrap{
          margin-top: 0.625rem;
          width: 1rem;
          height: 8.5rem;
          border: 0.0625rem solid rgba(173, 173, 173, 0.5);
          background-color: rgba(255, 255, 255, 0.15);
          position: relative;
          div{
            position: absolute;
            bottom: 0;
            width: 100%;
          }
          .progress{
            height: 80%;
            &.red{
              background-color: $red
            }
            &.white{
              background-color: $white
            }
            &.cyan{
              background-color: $cyan
            }
            &.orange{
              background-color: $orange
            }
          }
          .high{
            height: 90%;
            border-top: 0.0625rem dashed $red
          }
          .low{
            height: 30%;
            border-top: 0.0625rem dashed $red
          }
        }
      }
      .title-box{
        width: 100%;
        height: 2.75rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: .3125rem;
        .title-info{
          width: 8.0625rem;
          height: 100%;
          color: $light3Grey;
          font-size: .875rem;
          display: flex;
          justify-content: space-between;
          align-items: center;
          background-color: #1f2935;
          border-radius: 0.25rem;
          padding: 0 .625rem;
          box-sizing: border-box;
          .num-text{
            font-size: 1rem;
            color: $light3Grey;
          }
        }
      }
    }
  }
}
</style>
